<template>
  <div>
    <el-table ref="table" v-loading="loading" :data="list" style="width: 100%" border>
      <el-table-column width="50" label="序号" key="1" header-align="center" align="center">
        <template slot-scope="scope">
          <div>{{$parent.params.per_limit*($parent.params.page-1)+scope.$index+1}}</div>
        </template>
      </el-table-column>
      <el-table-column
        header-align="center"
        key="2"
        align="center"
        prop="id"
        label="退款单ID"
        width="100"
      ></el-table-column>
      <el-table-column
        key="3"
        header-align="center"
        align="center"
        prop="merchant_name"
        show-overflow-tooltip
        label="商户名称"
        width="170"
      ></el-table-column>
      <el-table-column
        key="4"
        header-align="center"
        align="center"
        prop="merchant_no"
        show-overflow-tooltip
        label="商户编号"
        width="160"
      ></el-table-column>
      <el-table-column
        key="5"
        header-align="center"
        align="center"
        prop="refund_no"
        show-overflow-tooltip
        label="退款单号"
        width="220"
      ></el-table-column>
      <el-table-column
        key="6"
        header-align="center"
        align="center"
        prop="order_no"
        label="退款订单号"
        width="220"
      ></el-table-column>
      <el-table-column
        key="7"
        header-align="center"
        align="center"
        prop="refund_amount"
        label="退款金额（元）"
        width="140"
      ></el-table-column>
      <el-table-column
        key="8"
        header-align="center"
        align="center"
        prop="refund_path"
        label="退款方式"
        show-overflow-tooltip
        width="130"
      ></el-table-column>
      <el-table-column
        key="9"
        header-align="center"
        align="center"
        prop="status_name"
        label="状态"
        width="110"
      ></el-table-column>
      <el-table-column
        key="10"
        v-if="status===2||status===''"
        header-align="center"
        align="center"
        prop="fail_reason"
        show-overflow-tooltip
        label="失败原因"
        width="150"
      ></el-table-column>
      <el-table-column
        key="11"
        header-align="center"
        align="center"
        prop="finished_at"
        label="完成时间"
        width="auto"
        min-width="140"
        v-if="status===1||status===''"
      ></el-table-column>
      <el-table-column
        key="12"
        header-align="center"
        align="center"
        prop="created_at"
        label="创建时间"
        width="140"
      ></el-table-column>
      <el-table-column
        key="13"
        header-align="center"
        align="center"
        fixed="right"
        label="操作"
        width="auto"
        min-width="120"
        v-if="status!==1"
      >
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.status==2&&searchInterface('orders_refunds.refund')"
            @click="againRefund(scope.row)"
            type="text"
          >重新发起退款</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
// 审核失败

import { againRefund } from '@/api/payment-order-admin/refund-order'
export default {
  props: {
    list: {
      type: Array,
      required: true
    },
    loading: {
      type: Boolean,
      required: true
    },
    status: {
      type: [Number, String],
      required: true
    },
    callback: {
      type: Function,
      required: false
    }
  },
  watch: {
    list() {
      setTimeout(() => {
        this.$refs.table.doLayout()
      })
    }
  },
  methods: {
    // 退款
    againRefund({ id }) {
      this.$confirm('确认重新发起退款吗?', '退款操作？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          againRefund(id).then(res => {
            this.$message({
              type: 'success',
              message: '已重新发起退款，请耐心等待'
            })
            this.callback(id)
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>